
<template>
    <el-form ref="ruleFormRef" :model="pastHistoryRuleForm" :rules="rules" label-width="200px" class="demo-ruleForm"
        :size="formSize" status-icon>
        <el-container class="patient-form-container">
            <el-form-item label="损伤机制" prop="injuryMechOption" class="patient-form-item" label-width="220px">
                <el-checkbox-group v-model="injuryMechOption">
                    <template v-for="(item, index) in injuryMechList" :key="index">
                        <el-checkbox :label="item.item_name" :value="item.item_code">{{ item.item_name }}</el-checkbox>
                    </template>
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="其他疾病" prop="otherDiscaseOption" class="patient-form-item" label-width="220px">
                <el-checkbox-group v-model="otherDiscaseOption">
                    <template v-for="(item, index) in otherDiscaseList" :key="index">
                        <el-checkbox :label="item.item_name" :value="item.item_code">{{ item.item_name }}</el-checkbox>
                    </template>
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="患膝感染史" prop="kneeInfectionHistoryOption" class="patient-form-item" label-width="220px">
                <el-checkbox-group v-model="kneeInfectionHistoryOption">
                    <template v-for="(item, index) in kneeInfectionHistoryList" :key="index">
                        <el-checkbox :label="item.item_name" :value="item.item_code">{{ item.item_name }}</el-checkbox>
                    </template>
                </el-checkbox-group>
            </el-form-item>
            <el-form-item label="传染病史" prop="infectionHistoryOption" class="patient-form-item" label-width="220px">
                <el-radio-group v-model="infectionHistoryOption">
                    <template v-for="(item, index) in infectionHistoryList" :key="index">
                        <el-radio :label="item.item_code">{{ item.item_name }}</el-radio>
                    </template>
                </el-radio-group>
            </el-form-item>
        </el-container>
    </el-form>
</template>

<script lang="ts" setup >
import { reactive, ref, onMounted, watchEffect } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
import { getLookUpByCode } from "../../axios/http"

interface RuleForm {
    name: string;
}

const formSize = ref('default')
const ruleFormRef = ref<FormInstance>()
const pastHistoryRuleForm = reactive<RuleForm>({
    name: ''
})

const rules = reactive<FormRules<RuleForm>>({
    name: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },

    ],
})

let injuryMechList: any = reactive([])
let otherDiscaseList: any = reactive([])
let kneeInfectionHistoryList: any = reactive([])
let infectionHistoryList: any = reactive([])

onMounted(async () => {
    await getFormInfo();
});


const injuryMechOption = ref([])
const otherDiscaseOption = ref([])
const kneeInfectionHistoryOption = ref([])
const infectionHistoryOption = ref('')

const getFormInfo = async () => {
    let painLableList = ['INJURY_MECHANISM', 'OTHER_DISEASE', 'KNEE_INFECTION_HISTORY'
        , 'INFECTION_HISTORY']
    painLableList.forEach(async (item) => {
        let res = await getLookUpByCode(item);
        switch (item) {

            case 'INJURY_MECHANISM':
                injuryMechList.push(...res);
                break;
            case 'OTHER_DISEASE':
                otherDiscaseList.push(...res);
                break;
            case 'KNEE_INFECTION_HISTORY':
                kneeInfectionHistoryList.push(...res);
                break;
            case 'INFECTION_HISTORY':
                infectionHistoryList.push(...res);
                break;
            default:
                break;
        }
    })

}

</script>

<style scoped lang='scss'>
.patient-form-container {
    width: 100%;
    display: flex;
    flex-direction: row;

    justify-content: flex-start;
    flex-wrap: wrap;
    align-content: flex-start;

    .patient-form-item {
        width: 100%;
    }

    .patient-form-container-item {
        width: 25%;
        display: flex;
        align-items: center;

        .patient-form-container-item-content {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;

            ::deep .el-input {
                width: 83% !important;
            }

            span {
                display: inline-block;
                flex: 1;
                text-align: right;
            }
        }
    }

    .patient-form-container-item-textarea {
        width: 50%;
    }
}

.knee-joint-activity {
    padding: 0px 15px 10px 15px;
    box-sizing: border-box;
}
</style>